package com.santu.edu.supporter.biz.order.controller;

import com.santu.edu.supporter.biz.order.pojo.dto.OrderDTO;
import com.santu.edu.supporter.biz.order.pojo.params.OrderAddParam;
import com.santu.edu.supporter.biz.order.pojo.params.OrderUpdateParam;
import com.santu.edu.supporter.biz.order.service.OrderService;
import com.santu.edu.supporter.biz.pay.pojo.dto.WxChatPayDTO;
import com.santu.edu.supporter.util.PageData;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author luoyaoqi
 * @createTime 2024/3/18
 * @description
 */
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("order")
public class OrderController {

    private final OrderService orderService;

    @PostMapping("add")
    public WxChatPayDTO addUserAddress(@RequestBody @Valid OrderAddParam addParam) {
        return orderService.addOrder(addParam);
    }

    /**
     * 修改订单地址
     *
     * @param updateParam
     * @return
     */
    @PostMapping("update")
    public Boolean updateUserAddress(@RequestBody @Valid OrderUpdateParam updateParam) {
        return orderService.updateOrder(updateParam);
    }

    @PostMapping("remove")
    public Boolean removeUserAddress(@NotBlank(message = "orderId不能为空") String orderId) {
        return orderService.removeOrder(orderId);
    }

    /**
     * 根据订单状态获取订单列表
     *
     * @param orderStatus
     * @return
     */
    @GetMapping("get/order/by/orderStatus")
    public PageData<OrderDTO> getUserAddressList(Integer orderStatus,
                                                 @RequestParam(defaultValue = "1") int page,
                                                 @RequestParam(defaultValue = "20") int size) {
        return orderService.getOrderList(orderStatus, page, size);
    }

}
